<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="${ctx!}/assets/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="${ctx!}/assets/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="${ctx!}/assets/css/animate.css" rel="stylesheet">
    <link href="${ctx!}/assets/css/style.css?v=4.1.0" rel="stylesheet">

</head>

<body>
        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-content">
                        <label style="text-align: right" class="col-sm-3 control-label">设备图片：</label>
                        <div class="row">
                            <div class="col-sm-offset-3 col-sm-6">
                                <form enctype="multipart/form-data" id="picForm">
                                    <input class="btn-primary" type="file" name="file">
                                <#--<input type="submit" value="upload"/>-->
                                </form>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-offset-3 col-sm-3">
                                <input type="button" class="btn-primary" id="picUpload" value="上传图片">
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-offset-3 col-sm-8">
                                <img style="height: 200px; width: auto" alt="" id="confPic">
                            </div>
                        </div>


                        <form class="form-horizontal m-t" id="frm" method="post" action="${ctx!}/admin/equipment/edit">
                        	<input type="hidden" id="id" name="id" value="${equipment.id}">
                            <input type="hidden" id="image" name="image" value="${equipment.image}">
                            <input type="hidden" id="project_id" name="project_id" value="${project.id}">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">设备组名称：</label>
                                <div class="col-sm-8">
                                    <input id="name" name="name" class="form-control" type="text" value="${equipment.name}" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">类型：</label>
                                <div class="col-sm-8">
                                    <select class="form_select form-control" id="type_id" name="type_id">
                                        <#list typeList as type>
                                            <option value="${type.id}" <#if type.name == equipment.type.typeName.name>selected="selected"</#if>>${type.name}</option>
                                        </#list>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">型号：</label>
                                <div class="col-sm-8">
                                    <input id="modelNum" name="modelNum" class="form-control" type="text" value="${equipment.modelNum}" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">管理人：</label>
                                <div class="col-sm-8">
                                    <input id="manager" name="manager" class="form-control" type="text" value="${equipment.manager}" >
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">系统分类：</label>
                                <div class="col-sm-8">
                                    <select class="form_select form-control" id="sysclass_id" name="sysclass_id">
                                        <option></option>
                                        <#list sysClasses as sysClass>
                                            <option value="${sysClass.id}" <#if equipment.sysClass.id == sysClass.id>selected="selected"</#if>>${sysClass.className}</option>
                                        </#list>
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 control-label">启用时间：</label>
                                <div class="col-sm-8">
                                    <input id="openTime" name="openTime" class="laydate-icon form-control layer-date" value="${equipment.openTime}">
                                </div>
                            </div>
                            <#--<div class="form-group">-->
                                <#--<label class="col-sm-3 control-label">设备组参数：</label>-->
                                <#--<div class="col-sm-8">-->
                                    <#--<textarea style="vertical-align: top; resize: none"  rows="5" id="content" name="content" class="form-control" type="text">${equipment.content}</textarea>-->
                                <#--</div>-->
                            <#--</div>-->



                            <div class="form-group">
                                <div class="col-sm-10 col-sm-offset-3 btn-box">
                                    <button class="btn btn-primary" type="submit">确认</button>
                                    <button class="btn btn-primary" onclick="back()" type="reset">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>



    <!-- 全局js -->
    <script src="${ctx!}/assets/js/jquery.min.js?v=2.1.4"></script>
    <script src="${ctx!}/assets/js/bootstrap.min.js?v=3.3.6"></script>

    <!-- 自定义js -->
    <script src="${ctx!}/assets/js/content.js?v=1.0.0"></script>

    <!-- jQuery Validation plugin javascript-->
    <script src="${ctx!}/assets/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/layer/layer.min.js"></script>
    <script src="${ctx!}/assets/js/plugins/layer/laydate/laydate.js"></script>
    <script type="text/javascript">
        console.log("${equipment.type.typeName.name}");
        laydate.render({
            theme: "#23b7e5",
            elem: '#openTime', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
            trigger: 'click',
            type: 'datetime',
        });
        function loadimg(img_id, url) {
            $(img_id).attr('src',"${ctx}" + url);
        }

        function upload_img(img_id, upload_id, form_id, input_id) {
            $(upload_id).on("click", function () {


                function progressHandlingFunction(e) {}

                function completeHandler(e) {
                    url = JSON.parse(e).message;
                    loadimg(img_id, url);
                    $(input_id).val(url);
                }

                var formData = new FormData($(form_id)[0]);
                $.ajax({
                    url: "${ctx!}/picUpload",  //Server script to process data
                    type: 'POST',
                    xhr: function() {  // Custom XMLHttpRequest
                        var myXhr = $.ajaxSettings.xhr();
                        if(myXhr.upload){ // Check if upload property exists
                            myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
                        }
                        return myXhr;
                    },
                    success: completeHandler,
                    data: formData,
                    cache: false,
                    contentType: false,
                    processData: false
                });
            });
        }

    $(document).ready(function () {
        <#if (equipment.image)??>
            loadimg("#confPic", "${equipment.image}");
        </#if>

        upload_img("#confPic", '#picUpload', "#picForm", "#image");
	    $("#frm").validate({
    	    rules: {
    	    	name: {
    	        required: true,
    	      },
                image: {
                    required: false,
                }
               //  content: {
    	      //   required: true,
    	      // }
    	    },
    	    messages: {},
    	    submitHandler:function(form){
    	    	$.ajax({
   	    		   type: "POST",
   	    		   dataType: "json",
   	    		   url: "${ctx!}/admin/equipment/edit",
   	    		   data: $(form).serialize(),
   	    		   success: function(msg){
	   	    			layer.msg(msg.message, {time: 2000},function(){
	   						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
	   						parent.layer.close(index);
	   					});
   	    		   }
   	    		});
            }
    	});
    });
    </script>

</body>

</html>
